#!/bin/bash
echo "mount vol for CentOS"
echo
echo "########################################"
echo "Press Ctrl + C to cancel              ##"
echo "Any key to continue                   ##"
echo "########################################"
read -n 1

creat_mkfs(){
read -p "please input your second vol device name(eg:sdd):" vol
fdisk /dev/$vol <<EOF
n
p
1
1

w
EOF
mkfs.ext4 /dev/${vol}1

read -p "please input your mount directory(eg:/data):" dir
if [ ! -d $dir ]; then
mkdir $dir
fi
mount /dev/${vol}1 $dir
uuid=$(blkid |grep /dev/${vol}1 |awk -F '\"' '{print $2}')
echo "UUID=$uuid	$dir	ext4	defaults	0 0" >> /etc/fstab

read -p "creat mkfs vol? y=continue n=exit : " a
if [ $a == 'y' ] || [ $a = 'Y' ]; then
con=0
elif [ $a == 'n' ] || [ $a = 'N' ]; then
con=1
echo
echo "#########################################"
echo "                                       ##"
echo " The operation completed! Please check ##"
echo "                                       ##"
echo "#########################################"
df -hT
cat /etc/fstab |grep UUID
exit
fi
}

read -p "please input your vol device name(eg:sdc):" vol
fdisk /dev/$vol <<EOF
n
p
1
1

w
EOF
mkfs.ext4 /dev/${vol}1

read -p "please input your mount directory(eg:/test):" dir
if [ ! -d $dir ]; then
mkdir $dir
fi
mount /dev/${vol}1 $dir
uuid=$(blkid |grep /dev/${vol}1 |awk -F '\"' '{print $2}')
echo "UUID=$uuid        $dir    ext4    defaults        0 0" >> /etc/fstab

read -p "creat mkfs vol? y=continue n=exit : " a
if [ $a == 'y' ] || [ $a = 'Y' ]; then
con=0
elif [ $a == 'n' ] || [ $a = 'N' ]; then
con=1
fi

while [ $con -eq 0 ]
do
creat_mkfs
done

